<?php

namespace app\admin\model;

/**
 *  经销商采购订单明细
 */


use think\Model;

class WholesalOrderItem extends BaseModel
{
    protected $name = 'order_item';
    protected $attributes = [
        'is_futures' => [
            0 => '现货',
            1 => '在途期货',
            2 => '大期货'
        ],
        'delivery_method' => [
            0 => '自提',
            1 => '快递',
            2 => '仓内过货'
        ],
        'prescription' => [
            1 => '普快',
            // 2 => '特快'
        ],
        'tax_package' => [
            1 => 'DDP',
            2 => 'DDU'
        ]
    ];

    protected $enumCallbacks = [
        'brand' => 'getBrandEnum',
        'category' => 'getCategoryEnum',
        'currency' => 'getCurrencyEnum',
        'warehouse' => 'getWarehouseEnum'
    ];

    public function getBrandEnum(){
        return ProductBrand::where('is_del',0)->column('id as value,name as label');
    }

    public function getCategoryEnum(){
        return ProductCategory::where('is_del',0)->column('id as value,name as label');
    }

    public function getCurrencyEnum(){
        return ProductCurrency::where('is_del',0)->column('id AS value,name as label');
    }

    public function getWarehouseEnum(){
        return Warehouse::where('is_del',0)->where('status',1)->column('id as value,name as label');
    }

    public function product()
    {
        return $this->hasOne(Product::class, 'id', 'product_id')->bind(['product_name' => 'cname', 'product_code' => 'code', 'brand', 'hashrate' , 'expiration_date']);
    }

    public function products()
    {
        return $this->hasOne(Product::class, 'id', 'product_id');
    }

    /* 仓库 */
    public function warehouses()
    {
        return $this->hasOne(Warehouse::class, 'id', 'warehouse_id');
    }


    public function getWarehouse()
    {
        return $this->hasOne(Warehouse::class, 'id', 'wid');
    }

    public function wholesalOrder()
    {
        return $this->belongsTo(WholesalOrder::class, 'order_id')->where('order_category','wholesal');
    }

    public function productForWhosal()
    {
        return $this->hasOne(Product::class, 'id', 'product_id')->bind(['product_name' => 'cname', 'code', 'brand', 'hashrate' , 'expiration_date']);
    }

    public function getFieldEnum($field,$arr = [])
    {
        return $this->getEnum($field,[],'label');
    }

}

